package com.mmp.main.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.mmp.common.util.SearchRequired;

/**
 * The persistent class for the user database table.
 *
 */
@Entity
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	private Integer id;

	@Column(name = "job_title")
	private String jobTitle;

	private String mobile;

	private String name;

	private Boolean statue;

	@SearchRequired
	private String password;

	@Column(name = "user_name")
	@SearchRequired
	private String userName;

	// bi-directional many-to-one association to HospitalDevice
	@OneToMany(mappedBy = "user")
	private List<HospitalDevice> hospitalDevices;

	// bi-directional many-to-one association to HospitalDeviceScrappingInfo
	@OneToMany(mappedBy = "user")
	private List<HospitalDeviceScrappingInfo> hospitalDeviceScrappingInfos;

	// bi-directional many-to-one association to JobOrder
	@OneToMany(mappedBy = "cancelledBy")
	private List<JobOrder> jobOrders1;

	// bi-directional many-to-one association to JobOrder
	@OneToMany(mappedBy = "closedBy")
	private List<JobOrder> jobOrders2;

	// bi-directional many-to-one association to Hospital
	@ManyToOne
	@JoinColumn(name = "hosp_id")
	private Hospital hospital;

	// bi-directional many-to-many association to SysRole
	@LazyCollection(LazyCollectionOption.FALSE)
	@ManyToMany
	@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
	private List<SysRole> sysRoles;

	// bi-directional many-to-one association to UserLogin
	// @OneToMany(fetch=FetchType.EAGER,fetch=FetchType.EAGER,mappedBy = "user")
	// private List<UserLogin> userLogins;

	// bi-directional many-to-one association to UserRole
	@OneToMany(mappedBy = "user")
	private List<UserRole> userRoles;

	@Column(name = "user_type")
	private Integer userType;

	public Integer getUserType() {
		return this.userType;
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}

	public User() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getJobTitle() {
		return this.jobTitle;
	}

	public void setJobTitle(String jobTitle) {
		this.jobTitle = jobTitle;
	}

	public String getMobile() {
		return this.mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Boolean getStatue() {
		return this.statue;
	}

	public void setStatue(Boolean statue) {
		this.statue = statue;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public List<HospitalDevice> getHospitalDevices() {
		return this.hospitalDevices;
	}

	public void setHospitalDevices(List<HospitalDevice> hospitalDevices) {
		this.hospitalDevices = hospitalDevices;
	}

	public HospitalDevice addHospitalDevice(HospitalDevice hospitalDevice) {
		getHospitalDevices().add(hospitalDevice);
		hospitalDevice.setUser(this);

		return hospitalDevice;
	}

	public HospitalDevice removeHospitalDevice(HospitalDevice hospitalDevice) {
		getHospitalDevices().remove(hospitalDevice);
		hospitalDevice.setUser(null);

		return hospitalDevice;
	}

	public List<HospitalDeviceScrappingInfo> getHospitalDeviceScrappingInfos() {
		return this.hospitalDeviceScrappingInfos;
	}

	public void setHospitalDeviceScrappingInfos(List<HospitalDeviceScrappingInfo> hospitalDeviceScrappingInfos) {
		this.hospitalDeviceScrappingInfos = hospitalDeviceScrappingInfos;
	}

	public HospitalDeviceScrappingInfo addHospitalDeviceScrappingInfo(
			HospitalDeviceScrappingInfo hospitalDeviceScrappingInfo) {
		getHospitalDeviceScrappingInfos().add(hospitalDeviceScrappingInfo);
		hospitalDeviceScrappingInfo.setUser(this);

		return hospitalDeviceScrappingInfo;
	}

	public HospitalDeviceScrappingInfo removeHospitalDeviceScrappingInfo(
			HospitalDeviceScrappingInfo hospitalDeviceScrappingInfo) {
		getHospitalDeviceScrappingInfos().remove(hospitalDeviceScrappingInfo);
		hospitalDeviceScrappingInfo.setUser(null);

		return hospitalDeviceScrappingInfo;
	}

	public List<JobOrder> getJobOrders1() {
		return this.jobOrders1;
	}

	public void setJobOrders1(List<JobOrder> jobOrders1) {
		this.jobOrders1 = jobOrders1;
	}

	public JobOrder addJobOrders1(JobOrder jobOrders1) {
		getJobOrders1().add(jobOrders1);
		jobOrders1.setCancelledBy(this);

		return jobOrders1;
	}

	public JobOrder removeJobOrders1(JobOrder jobOrders1) {
		getJobOrders1().remove(jobOrders1);
		// jobOrders1.setUser1(null);
		jobOrders1.setCancelledBy(null);

		return jobOrders1;
	}

	public List<JobOrder> getJobOrders2() {
		return this.jobOrders2;
	}

	public void setJobOrders2(List<JobOrder> jobOrders2) {
		this.jobOrders2 = jobOrders2;
	}

	public JobOrder addJobOrders2(JobOrder jobOrders2) {
		getJobOrders2().add(jobOrders2);
		jobOrders2.setClosedBy(this);

		return jobOrders2;
	}

	public JobOrder removeJobOrders2(JobOrder jobOrders2) {
		getJobOrders2().remove(jobOrders2);
		jobOrders2.setClosedBy(null);

		return jobOrders2;
	}

	public Hospital getHospital() {
		return this.hospital;
	}

	public void setHospital(Hospital hospital) {
		this.hospital = hospital;
	}

	public List<SysRole> getSysRoles() {
		return this.sysRoles;
	}

	public void setSysRoles(List<SysRole> sysRoles) {
		this.sysRoles = sysRoles;
	}

	// public List<UserLogin> getUserLogins() {
	// return this.userLogins;
	// }

	// public void setUserLogins(List<UserLogin> userLogins) {
	// this.userLogins = userLogins;
	// }

	// public UserLogin addUserLogin(UserLogin userLogin) {
	// getUserLogins().add(userLogin);
	// userLogin.setUser(this);
	//
	// return userLogin;
	// }

	// public UserLogin removeUserLogin(UserLogin userLogin) {
	// getUserLogins().remove(userLogin);
	// userLogin.setUser(null);
	//
	// return userLogin;
	// }

	public List<UserRole> getUserRoles() {
		return this.userRoles;
	}

	public void setUserRoles(List<UserRole> userRoles) {
		this.userRoles = userRoles;
	}

	public UserRole addUserRole(UserRole userRole) {
		getUserRoles().add(userRole);
		userRole.setUser(this);

		return userRole;
	}

	public UserRole removeUserRole(UserRole userRole) {
		getUserRoles().remove(userRole);
		userRole.setUser(null);

		return userRole;
	}

}
